<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
class CartController extends Controller{
	
	private $GoodsListModel;
	private $GoodsAttrModel;
	private $TypeAttrModel;
	
	public function __init(){
		$this->GoodsListModel=M('\Common\Model\sc_goods_list');
		$this->GoodsAttrModel=M('\Common\Model\sc_goods_attr');
		$this->TypeAttrModel=M('\Common\Model\sc_typeAttr');
		
	}
	
	
	
	public function index(){
	
	    //P($_SESSION['cart']);
	    if(isset($_SESSION['cart'])){
		    $data= $_SESSION['cart']['goods']; 
			$taids=[];
			foreach($data as $k=>$v){
				$gtids=implode(",", $v['options']['options']);
	            $data[$k]['vdata']=$this->GoodsAttrModel->where("gtid IN ({$gtids})")->get();
				
				foreach($data[$k]['vdata'] as $kk=>$v){
					$data[$k]['vdata'][$kk]['taname']=$this->TypeAttrModel->where('taid',$data[$k]['vdata'][$kk]['sc_type_attr_taid'])->pluck('taname');
				}
			}
		}else{
			
			$data=[];
			
		}
		
		//P($data);
		
		View::with('data',$data);
		
		View::make();
	}
	
	//删除购物车一个商品
	public function delOne(){
		
		$CartId=Q('get.CartId');
		//P($CartId);
		unset($_SESSION['cart']['goods'][$CartId]);
		
		echo 1;
	}
	
	
	public function add(){
		
		//添加购物车
		Cart::add(Q('post.'));
	}
	
	
}
?>